var util = require("../../../utils/util.js"),
{api} = require("../../../utils/api.js"),
    app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pageSize: 10,
        page: 1,
        list: [],
        proScroll: false,
        showEmpty: false,
        activeIndex: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.doctorList();
    },
    async doctorList() {
        let {
            data: {
                list
            }
        } = await api.doctorList({
            page: this.data.page,
            pageSize: this.data.pageSize,
            type:this.data.activeIndex
        });
        let listArr = list.data && Array.isArray(list.data) ? list.data : [];
        this.setData({
            proScroll: listArr.length < this.data.pageSize ? true : false,
            list: this.data.page == 1 ? listArr : [...this.data.list, ...listArr],
            showEmpty: list.total == 0 ? true : false
        })
    },
    onReachBottom() {
        if (!this.data.proScroll) {
            let page = this.data.page;
            page = page + 1;
            this.setData({
                page: page
            })
            this.doctorList();
        }
    },

    navMethod(e) {
        let {
            index
        } = e.currentTarget.dataset;
        this.setData({
            page: 1,
            activeIndex:index
        })
        this.doctorList();
    },

    gotodetail(e) {
        let {
            id
        } = e.currentTarget.dataset;
        wx.navigateTo({
            url: '/pages/expertTeam/detail/detail?id='+id,
        })
    },
    onShareAppMessage(e) {
        return util.shareEvent(e)
      }
})